<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		// TODO 5 -sse 单工通讯
		const sse = new EventSource('http://localhost:8000/sse')

		// 监听消息 默认 message ，最好用这种，如果修改了纤细类型，下面哪种获取不到消息
		sse.addEventListener('test', (e) => {
			console.log(e);
		})
		// sse.onmessage = e => {
		// 	console.log(e);
		// };


		sse.onopen = e => {
			console.log('SSE connection opened,5s断开连接');
		};


		sse.onerror = e => {
			console.error('SSE connection failed');
		};

		setTimeout(() => {
			sse.close()
		}, 5000)
	</script>
</body>

</html>
